package app.beit.finportal.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import app.beit.finportal.entity.Slides;

public class SlidesDao extends BaseDao<Slides>{
	
	@SuppressWarnings("unchecked")
	public List<Slides> getAllBackdoor() throws Exception{
		final Session session = super.sessionFactory.openSession();
		final List<Slides> result = session.createQuery("from Slides").list();
		session.close();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public List<Slides> getAll() throws Exception{
		final Session session = super.sessionFactory.openSession();
		final List<Slides> result = session.createQuery("from Slides n where n.status='1' order by updated_date desc").list();
		session.close();
		
		return result;
	}
	
	@SuppressWarnings("unchecked")
	public List<Slides> getAllLastestDate() throws Exception{
		final Session session = super.sessionFactory.openSession();
		final Query q = session.createQuery("from Slides n where n.status='1' order by updated_date desc");
		q.setFirstResult(0);
		q.setMaxResults(3);
		final List<Slides> result = q.list();
		session.close();
		
		return result;
	}
	
	public Slides getById(final String id) throws Exception{
		final Session session = super.sessionFactory.openSession();
		final Slides result = (Slides) session.createQuery("from Slides n where id='" + id + "' ").uniqueResult();
		session.close();
		
		return result;
	}
}
